<table class="site_sysroles">
</table>
<div class="easyui-window" id="site_sysroles_treewindow" title="权限列表" style="width:600px;height:370px"
     data-options="iconCls:'icon-save',modal:true,closed:true">
    <table id="site_sysroles_tree" >
    </table>
</div>
<script>
    $(function(){
        site_sysroles_showGrid();
        site_sysroles_loadTree();
    });
    function site_sysroles_showGrid(){
        $(".site_sysroles").datagrid({
            url:'../site-roles/loadList.action',
            method:'post',
            fitColumns:true,
            columns:[[
                {field:'role',title:'用户名',width:100},
                {field:'description',title:'角色名称',width:100},
            ]],
            toolbar: [{
                iconCls: 'icon-add',
                handler: function(){
                    loadCurrent('添加角色','../site-roles/showadd.action');
                }
            },{
                iconCls: 'icon-edit',
                handler: function(){
                    var selected = $(".site_sysroles").datagrid("getSelected");
                    if(selected==null){
                        $.messager.alert('警告','请选择一行记录');
                    }else{
                        //进行删除操作
                        loadCurrent('编辑角色','../site-roles/showedit.action?id='+selected.id);
                    }
                }
            },{
                iconCls: 'icon-remove',
                handler: function(){
                    var selected = $(".site_sysroles").datagrid("getSelected");
                    if(selected==null){
                        $.messager.alert('警告','请选择一行记录');
                    }else{
                        //进行删除操作
                        $.ajax({
                            type: "POST",
                            url: '../site-roles/delete.action',
                            data:JSON.stringify({'id':selected.id}),
                            contentType: "application/json; charset=utf-8",
                            dataType: 'json',
                            success: function(res){
                                if(res.code == 10000){
                                    //删除成功重新加载页面
                                    loadCurrent('角色管理','../site-roles/index.action');
                                }
                            },
                            error: function(res){

                            }
                        });
                    }
                }
            }],
            fit:true,
            border:false,
            doSize:true
        });
    }
    function site_sysroles_loadTree(){
        $("#site_sysroles_tree").treegrid({
            url:'../site-roles/loadPermissionsList.action',
            method:'post',
            fitColumns:true,
            idField:'id',
            treeField:'menuname',
            columns:[[
                {field:'menuname',title:'菜单名称',width:100},
            ]],
            fit:true,
            border:false,
            doSize:true,
            checkbox:true
        });
        $("#site_sysroles_treewindow").window({
            onOpen:function(){
                $("#site_sysroles_tree").treegrid("resize");
            },
            onClose:function(){
                //将tree进行checkbox，进行clear
                $('#site_sysroles_tree').treegrid('clearChecked');
            }
        });
    }
</script>